import user.ProxyUser;
import user.User;
import user.factory.AdminUserFactory;
import user.factory.NormalUserFactory;

import java.util.Scanner;

public class LibrarySystem {
    public static void main(String[] args) {
        // 工厂模式
        AdminUserFactory adminUserFactory = new AdminUserFactory();
        User adminUser = adminUserFactory.createUser("zhangsan", 1);

        NormalUserFactory normalUserFactory = new NormalUserFactory();
        User normalUser1 = normalUserFactory.createUser("lisi", 2);
        User normalUser2 = normalUserFactory.createUser("wangwu", 3);

        // 代理模式(控制对象的访问)
        ProxyUser proxyUser = new ProxyUser(adminUser);
        ProxyUser proxyUser1 = new ProxyUser(normalUser1);
        ProxyUser proxyUser2 = new ProxyUser(normalUser2);

        LibrarySystem librarySystem = new LibrarySystem();
        ProxyUser currentUser = librarySystem.selectProxyRole(proxyUser, proxyUser1, proxyUser2);

        while (true){
            int choice = currentUser.getRealUser().display();
            currentUser.handleOperation(choice);
        }


    }

    public ProxyUser selectProxyRole(ProxyUser proxyUserAdmin, ProxyUser proxyUserNormal1, ProxyUser proxyUserNormal2){
        System.out.println("选择角色进行登录：");
        System.out.println("1.管理员\n2.普通用户(lisi)\n3.普通用户(wangwu)\n4.退出系统");
        ProxyUser currentUser = null;
        Scanner scanner = new Scanner(System.in);
        int choice = scanner.nextInt();
        switch (choice){
            case 1:
                currentUser = proxyUserAdmin;
                break;
            case 2:
                currentUser = proxyUserNormal1;
                break;
            case 3:
                currentUser = proxyUserNormal2;
                break;
            case 4:
                System.exit(0);
                System.out.println("系统已退出");
                break;
            default:
                break;
        }

        return currentUser;
    }
}
